package leecode.stringAndArray.summary;

import java.util.ArrayList;
import java.util.List;

/*给定一个非负索引 rowIndex，返回「杨辉三角」的第 rowIndex 行。*/
public class YangHuiGenerate2 {
    public static void main(String[] args) {
        List<Integer> row = getRow(5);
        System.out.println(row);
    }

    public static List<Integer> getRow(int rowIndex) {
        List<Integer> before = new ArrayList<>();
        for (int i = 0; i <= rowIndex; i++) {
            List<Integer> after = new ArrayList<>();
            for (int j=0; j<=i; j++){
                if(j==0 ||j==i){
                    after.add(1);
                }else {
                    after.add(before.get(j)+before.get(j-1));
                }
            }
            before=after;
        }
        return before;
    }
}
